package kr.or.kosta.otr.persistence.companyreview;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.annotation.Resource;

import kr.or.kosta.otr.vo.CompanyReviewVO;
import kr.or.kosta.otr.vo.CompanyVO;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository("CompanyReviewDao")
public class CompanyReviewDaoImpl implements CompanyReviewDao{
	@Resource(name="sqlMapClient")
	private SqlMapClient sqlMapClient;
	
	
	@Override
	public int writeCompanyReview(CompanyReviewVO vo) throws SQLException {
		return (int) sqlMapClient.insert("CompanyReview.writeCompanyReview", vo);
	}

	@Override
	public void deleteCompanyReview(int company_review_id) throws SQLException {
		sqlMapClient.delete("CompanyReview.deleteCompanyReview", company_review_id);
	}

	@Override
	public CompanyReviewVO getOneCompanyReviewById(int companyReviewId) throws SQLException {
		return (CompanyReviewVO)sqlMapClient.queryForObject("CompanyReview.getOneCompanyReviewById", companyReviewId);
	}

	@Override
	public ArrayList<CompanyReviewVO> getAllCompanyReview() throws SQLException {
		return (ArrayList<CompanyReviewVO>)sqlMapClient.queryForList("CompanyReview.getAllCompanyReview");
	}

	@Override
	public CompanyReviewVO getCompanyReviewByScoreId(int scoreId)
			throws SQLException {
		return (CompanyReviewVO)sqlMapClient.queryForObject("CompanyReview.getCompanyReviewByScoreId", scoreId);
	}

	@Override
	public ArrayList<CompanyReviewVO> getAllCompanyReviewByUserId(String userId)
			throws SQLException {
		ArrayList<CompanyReviewVO> list = (ArrayList<CompanyReviewVO>)sqlMapClient.queryForList("CompanyReview.getAllCompanyReviewByUserId", userId);
		return list;
	}

	@Override
	public CompanyReviewVO getRecentCompanyReview() throws SQLException {
		CompanyReviewVO vo = (CompanyReviewVO)sqlMapClient.queryForObject("CompanyReview.getRecentCompanyReview");
		return vo;
	}

	@Override
	public void deleteCompanyReviewByUser(HashMap<String, Object> map)
			throws SQLException {
		//companyReviewId , companyReviewPassword, companyReviewUserId 를 맵에 입력 할 것
		sqlMapClient.delete("CompanyReview.deleteCompanyReviewByUser", map);
		
	}

	@Override
	public ArrayList<CompanyReviewVO> getCompanyReviewByCompanyName(
			String companyName) throws SQLException {
		ArrayList<CompanyReviewVO> list = (ArrayList<CompanyReviewVO>) sqlMapClient.queryForList("CompanyReview.getCompanyReviewByCompanyName", companyName);
		return list;
	}
	
	//main
	@Override
	public int getTopSalaryCompanyId() throws SQLException {
		return (int)sqlMapClient.queryForObject("CompanyReview.getTopSalaryCompanyId");
	}

	@Override
	public int getHotCompanyId() throws SQLException {
		return (int)sqlMapClient.queryForObject("CompanyReview.getHotCompanyId");
	}

	@Override
	public int getRecentReviewedCompanyId() throws SQLException {
		return (int)sqlMapClient.queryForObject("CompanyReview.getRecentReviewedCompanyId");
	}
}
